//
//  VisitorTableView.swift
//  新浪微博
//
//  Created by seteny on 16/7/9.
//  Copyright © 2016年 seteny. All rights reserved.
//

import UIKit

class VisitorTableView: UITableViewController {

    //登陆标识
    var isLogin: Bool = UserAccountViewModel.shareUserAccount.isLogin
    
   
    
    //访客视图
    var visitorView: VisitorView?
    
    
    override func loadView() {
        if isLogin {
            super.loadView()
        } else {
            
            //未登录 提供访客视图
            visitorView = VisitorView()
            //使用[weak self]解决闭包循环引用
            visitorView?.loginClosure = { [weak self] in
                
                self?.showOAuthLogin()
            }
            
            view = visitorView
            
            
            setupNavUI()
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    
   private func setupNavUI() {
        
       navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", target: self, action: "loginAction")
        
    }
    
    
    
   @objc private func registerAction() {
        showOAuthLogin()
    }
    
    
    @objc private func loginAction() {
        showOAuthLogin()
    }
    
    
    //OAuth授权登陆页面
    private func showOAuthLogin() {
        
        let OAuthVC = OAuthViewController()
        let nav = UINavigationController(rootViewController: OAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}

